﻿using SchedulerManager;
using SchedulerManager.Common;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ApiServer.Utilitys.SchedulerExt
{
    public static class SchedulerCenterExtenion
    {
        public static IServiceCollection AddSchedulerServices(this IServiceCollection services, IConfiguration configuration)
        {
            services.Configure<DatabaseSettings>(configuration.GetSection("QuartZDatabase"));

            services.AddSingleton<ISqlSugarClient>(provider =>
            {
                var settings = configuration.GetSection("QuartZDatabase").Get<DatabaseSettings>();
                return new SqlSugarClient(new ConnectionConfig
                {
                    ConnectionString = settings.ConnectionString,
                    DbType = (DbType)settings.DbType,
                    IsAutoCloseConnection = true
                });
            });

            services.AddSingleton<SchedulerCenter>();
            return services;
        }
    }
}
